class BlogPostsController < ApplicationController 

 	def index
     @blog_posts = BlogPost.all
   end
	def searchByTitle1
     @blog_posts = BlogPost.where(title: "untitled")
   end
  def searchByTitle
     @blog_posts.searchByTitle("untitled")
	 end
	def searchallin
		@blog_posts = BlogPost.all_in(title: ["titled"])
   end
	def search2
     @blog_posts = BlogPost.search2(params[:search])
   end


#Here all expressions inside the bracket must be true
def allof  
	@blog_posts = BlogPost.all_of(tag1: "a", tag2: "b")
end

# The variable's value must match ANY of the values. In this example, any blogpost having tag1 = a or b will be selected. 
#Note the difference between any_in and also_in. The first returns the inetersection of the matches while the latter returns the union.


def alsoin
	@blog_posts = BlogPost.also_in(tag1: [ "a", "b" ])
end

# you can sort ascendingly and desc using the body of the following method:
	def sortasc
		@blog_posts = BlogPost.asc(:title)
# another way: BlogPost.ascending(:first_name) .. similarly there is desc
	end

	def getdistinct
# Get the distinct values for tag1. Note that BlogPost.all only gets all entries.
		@blog_posts = BlogPost.all.distinct(:tag1)
	end

#gets all entries except those matching the conditions in the brackets. Here it matches all blogPosts with titles different from untitled and content different from "no content entered" 
	def exclude 
		@blog_posts = BlogPost.excludes(title: "untitled", content: "no content entered")
	end

#did not get include yet!!

# Only return 2 documents.

	def limit
		@blog_posts =BlogPost.limit(params[:num])
	end

	#Model.near requires 2D index on the provided field. Find locations that are near the supplied coordinates. I did not get it awy.

# Match all BlogPosts without tag1 a or b and without tag2 a or b.
	def notin
		@blog_posts = BlogPost.not_in(tag1: [ "a", "b" ], tag2: ["a","b"])
	end

 	def show
     @blog_post = BlogPost.find(params[:id])
   end

 	def new
     @blog_post = BlogPost.new

   end
 
	def post
     @blog_post = BlogPost.new
     @blog.save
   end


	def edit
     @blog_post = BlogPost.find(params[:id])
     @blog_post.update_attributes(params[:blog_post])
	redirect_to @blog_post
   end

	def update
     @blog_post = BlogPost.find(params[:id])
     @blog_post.update_attributes(params[:blog_post])
   end

 	def create
     @blog_post = BlogPost.new(params[:blog_post])
     @blog_post.save
     redirect_to @blog_post
   end
	
	def destroy
     @blog_post = BlogPost.find(params[:id])
     @blog_post.destroy
     redirect_to blog_posts_url
   end
end
